package ricky.loader.protocol
{
	import flash.display.LoaderInfo;
	import flash.events.Event;
	import flash.system.ApplicationDomain;
	import flash.system.LoaderContext;
	
	import ricky.Interface.IDecoder;
	import ricky.Interface.ILoadComplete;
	import ricky.loader.Request;
	
	public class DisplayDecoder implements IDecoder
	{
		public function DisplayDecoder()
		{
		}
		
		public function doDecoder(req:Request, onComplete:ILoadComplete):void
		{
			var my:MyLoader=new MyLoader();	
			my.contentLoaderInfo.addEventListener(Event.COMPLETE,onCompelete);
			my.req=req;
			my.loadComplete=onComplete;
			var loadcon:LoaderContext=new LoaderContext(false,ApplicationDomain.currentDomain,null);//指定域名	
			loadcon.allowCodeImport=true;
			my.loadBytes(req.data,loadcon);
		}
		
		/**
		 * 解码完成
		 */
		private function onCompelete(e:Event):void
		{
			var my:MyLoader=(e.currentTarget as LoaderInfo).loader as  MyLoader;
			var req:Request=my.req;
			req.data= e.currentTarget.content;
			my.loadComplete.doComplete(req);
			
		}
	}
}